#include "CmnServer.h"

Account::Account(void):_logged_(false),_signedUp_(false){}
Account::Account(string passWord_)
{
	_tempWord_="none";
	_passWord_=passWord_;
	_signedUp_=true;
}
bool Account::CheckTempWord(string tempPass_){
	if(_tempWord_==tempPass_)return true;
	else return false;
}
bool Account::sign_in(string& password_){
	if(_passWord_==password_){
		_LARGE_INTEGER li; QueryPerformanceCounter(&li), srand(li.LowPart);
		__int8 a[21];
		for(__int32 k=0;k<20;k++)a[k]='!'+rand()%('~'-'!');	a[20]='\0';
		password_=a;
		_tempWord_=a;
		_logged_=true;
		return true;
	}
	else return false;
}
bool Account::CheckSigned(){
	return _logged_;
}

bool Account:: sign_out(string tempWord_){
	if(_logged_){
		_logged_=false;
		return true;
	}
	return false;
}

/*bool Account:: delete_account(string tempWord_){
	if(_tempWord_==tempWord_&&_logged_){
		_logged_=false;

		return true;
	}
	return false;
}*/
bool Account:: ADD_FRIEND(string user_name_,string friend_name_,multimap<string, string> &friend_list,multimap<string, string> &requests)
{
	if(_logged_){friends.Add_Friend(user_name_, friend_name_,friend_list,requests);
	return true;}
	return false;
}
bool Account:: REMOVE_FRIEND(string user_name_,string friend_name_,multimap<string, string> &friend_list,multimap<string, string> &requests)
{
	if(_logged_){friends.Remove_Friend(user_name_, friend_name_,friend_list,requests);
	return true;}
	return false;
}
bool Account:: CANCEL_REQUEST(string user_name_,string friend_name_,multimap<string, string> &friend_list,multimap<string, string> &requests)
{
	if(_logged_){friends.cancel_request(user_name_, friend_name_,friend_list,requests);
	return true;}
	return false;
}
bool  Account:: SHOW_FRIEND(string user_name_,string& UserFriends,multimap<string, string> &friend_list)
{
	if(_logged_){
		UserFriends=friends.Show_Friend(user_name_,friend_list);
	return true ;}
	return false;
}
bool  Account:: SHOW_REQUEST(string user_name_,string& UserRequests,multimap<string, string> &requests)
{
	if(_logged_)
	{
		UserRequests=friends.Show_request(user_name_,requests);
		return true ;
	}
	return false;
}
Account::~Account(void)
{
}


//---------------------Amr Shibiny------------------------------begin
	void Account::addevent(char name_[50] , int start_hour , int start_minute , int start_day , int start_month , int start_year  , int end_hour , int end_minute , int end_day, int end_month, int end_year )
	{
		
		event x(name_, start_hour , start_minute ,  start_day ,  start_month ,  start_year  ,  end_hour ,  end_minute ,  end_day,  end_month,  end_year );
		events.push_back(x);
	}
	list<event>::iterator Account::findevent(char* tar)
	{
		list<event>::iterator found = events.begin();
		for(; found!=events.end(); found++)
		{
			if(!strcmp(tar, found->geteventname()))return found;
		}
	}
	void Account::Invitepeople( char* nameevent, char** people, int num)
	{
		list<event>::iterator p = findevent(nameevent);
		p->Invitepeople(people, num);
	}
	char* Account::getstarttime(char* nameevent)
	{
		list<event>::iterator p = findevent(nameevent);
		return p->getstarttime();
	}
	char* Account::getendtime(char* nameevent)
	{
		list<event>::iterator p = findevent(nameevent);
		return p->getendtime();
	}
	char** Account::getinvitedpeople(char* nameevent)
	{
		list<event>::iterator p = findevent(nameevent);
		return p->getinvitedpeople();
	}
	void Account::edit_start(char* nameevent, int hour, int minute, int day, int month, int year)
	{
		list<event>::iterator p = findevent(nameevent);
		p->edit_start(hour, minute, day, month, year);
	}
	void Account::edit_end(char* nameevent, int hour, int minute, int day, int month, int year)
	{
		list<event>::iterator p = findevent(nameevent);
		p->edit_end(hour, minute, day, month, year);
	}
	void Account::goingperson(char* nameevent, char* one)
	{
		list<event>::iterator p = findevent(nameevent);
		p->goingperson(one);
	}
	void Account::notgoingperson(char*nameevent, char *one )
	{
		list<event>::iterator p = findevent(nameevent);
		p->notgoingperson(one);
	}

	void Account::deleteevent(string name_)
	{
		list<event>::iterator p = findevent((char*)name_.c_str());
		events.erase(p);
	}

//---------------------Amr Shibiny------------------------------end

	